package com.crazy.service.sys.impl;

import static com.alibaba.fastjson.JSON.toJSONString;

import java.util.ArrayList;
import java.util.Collection;

import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.crazy.common.ztree.TreeNode;
import com.crazy.entity.sys.PubResource;
import com.crazy.entity.sys.PubRole;
import com.crazy.service.sys.PubRoleService;

/**
 * 角色Service实现类
 * 
 * @author Zhang Weiwei
 * @since 2013-9-20下午1:51:06
 */
@Service
@Transactional
public class PubRoleServiceImpl extends BaseServiceImpl<PubRole> implements
		PubRoleService {

	@Override
	public String listToJsonStringForUpdate(Collection<PubResource> allList,
			Collection<PubResource> selectList) {
		Collection<TreeNode> nodes = new ArrayList<TreeNode>();
		TreeNode node = null;
		for (PubResource res : allList) {
			node = new TreeNode();
			node.setId(res.getResourceId());
			node.setName(res.getResourceName());
			if (res.getPubResource() != null) {
				node.setpId(res.getPubResource().getResourceId());
			}
			for (PubResource select : selectList) {
				if (select.getResourceId().equals(res.getResourceId())) {
					node.setChecked(true);
					break;
				}
			}
			node.setOpen(true);
			nodes.add(node);
		}
		String jsonString = toJSONString(nodes);
		return jsonString;
	}
}
